Skip to content

kubernetes: clean up temporary provisioning scripts on the management server#13592

Open
nikolauseppinger wants to merge 1 commit into
apache:mainfrom
nikolauseppinger:kubernetes/cleanup-temp-provisioning-scripts
Open

kubernetes: clean up temporary provisioning scripts on the management server#13592
nikolauseppinger wants to merge 1 commit into
apache:mainfrom
nikolauseppinger:kubernetes/cleanup-temp-provisioning-scripts

Conversation

@nikolauseppinger

@nikolauseppinger nikolauseppinger commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description

The CKS action workers copy provisioning scripts to the cluster nodes via
retrieveScriptFiles() + copyScripts() / copyScriptFile(). Each script is
written to a local temp file with File.createTempFile(filename, ".sh") in
retrieveScriptFile(), but that local copy on the management server is never
deleted
after it has been SCP'd to the node.

As a result, every cluster deploy, provider/CSI deploy, autoscale enable, PV
cleanup and Kubernetes upgrade leaks one *.sh file per script into the
management server's temp directory, growing without bound over the cluster
lifetime:

-rw-r--r--. 1 cloud cloud 3230 ... autoscale-kube-cluster10402639792822688389.sh
-rw-r--r--. 1 cloud cloud 7197 ... delete-pv-reclaimpolicy-delete10664788910304997694.sh
-rw-r--r--. 1 cloud cloud 2303 ... deploy-cloudstack-secret10522058804386657778.sh
-rw-r--r--. 1 cloud cloud 1811 ... deploy-csi-driver1118819744193036791.sh
-rw-r--r--. 1 cloud cloud 1472 ... deploy-provider10072339396849174814.sh
-rw-r--r--. 1 cloud cloud 4971 ... upgrade-kubernetes.sh10982436999748062804.sh
... (dozens more, one set per CKS action)

This PR adds cleanupScriptFiles() / deleteScriptFileQuietly() to the base
KubernetesClusterActionWorker and invokes it in a finally block around
every copy site:

  • KubernetesClusterActionWorker.deployProvider()
  • KubernetesClusterActionWorker.deployCsiDriver()
  • KubernetesClusterResourceModifierActionWorker.autoscaleCluster()
  • KubernetesClusterResourceModifierActionWorker.deletePVsWithReclaimPolicyDelete()
  • KubernetesClusterUpgradeWorker (overrides cleanupScriptFiles() to also remove
    its upgrade-kubernetes.sh temp file, cleaned up after the per-node upgrade loop
    completes since the same file is reused across nodes)

There is no functional change to the provisioning itself: the scripts are still
written, copied and executed exactly as before; only the leftover local copies
on the management server are removed once they have been transferred.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Bug Severity

  • Minor

Observed on a CloudStack 4.22.1 management server running CKS clusters; the code
path is unchanged on main.

… server

The CKS action workers copy provisioning scripts (deploy-cloudstack-secret,
deploy-provider, deploy-csi-driver, delete-pv-reclaimpolicy-delete,
autoscale-kube-cluster and upgrade-kubernetes.sh) to the cluster nodes via
retrieveScriptFiles() + copyScripts()/copyScriptFile(). Each script is written
to a local temp file via File.createTempFile(), but that local copy is never
deleted after it has been SCP'd to the node.

As a result every cluster deploy, provider/CSI deploy, autoscale enable, PV
cleanup and Kubernetes upgrade leaks one *.sh file per script into the
management server's temp directory, growing without bound over the cluster
lifetime. On a long-running management server this accumulates to hundreds of
stale scripts in /tmp.

This adds cleanupScriptFiles()/deleteScriptFileQuietly() to the base action
worker and invokes it in a finally block around every copy site
(deployProvider, deployCsiDriver, autoscaleCluster, deletePVsWithReclaimPolicyDelete
and the upgrade worker), so the local temp copies are removed once they have
been transferred to the node. The upgrade worker additionally removes its
upgrade-kubernetes.sh temp file after the node loop completes.

No functional change to the provisioning itself: the scripts are still written,
copied and executed exactly as before; only the leftover local copies are
deleted.

Covered by new unit tests for cleanupScriptFiles()/deleteScriptFileQuietly()
(temp files deleted, null/missing files handled without throwing).
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 23.07692% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 19.47%. Comparing base (a503a52) to head (9f72e75).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
...KubernetesClusterResourceModifierActionWorker.java 0.00% 15 Missing ⚠️
...r/actionworkers/KubernetesClusterActionWorker.java 52.94% 7 Missing and 1 partial ⚠️
.../actionworkers/KubernetesClusterUpgradeWorker.java 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main   #13592   +/-   ##
=========================================
  Coverage     19.47%   19.47%           
- Complexity    19351    19355    +4     
=========================================
  Files          6296     6296           
  Lines        568368   568394   +26     
  Branches      69622    69622           
=========================================
+ Hits         110673   110717   +44     
+ Misses       445618   445597   -21     
- Partials      12077    12080    +3     
Flag Coverage Δ
uitests 3.44% <ø> (ø)
unittests 20.74% <23.07%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant